//
//  YZMBundleVersionControlService.m
//  YZMicroStock
//
//  Created by apple on 17/7/27.
//  Copyright © 2017年 cqjr. All rights reserved.
//

#import "YZMBundleVersionControlService.h"
#import "YZClient+Home.h"
#import "YZGeneralResultModel.h"
#import "JSONBaseDeal.h"

@implementation YZMBundleVersionControlService{
    
    NSDictionary *_dataDic;
}

+ (instancetype)sharedService {
    
    static YZMBundleVersionControlService *instance = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        
        instance = [[self alloc] init];
        instance.isRun = NO;
    });
    
    return instance;
}

- (void)fecthBundVersion {
    
    WS(ws)
    [YZClient checkSoftwareUpdateSuccess:^(NSURLResponse *response, id responseObject) {
        
        YZGeneralResultModel *topModel = responseObject;
        if (topModel.success) {
            _dataDic = topModel.data;
            if ([_dataDic.allKeys containsObject:@"buildVersion"]) {
                NSNumber *numVersion = [_dataDic objectForKey:@"buildVersion"];
                if (numVersion == nil) {
                    numVersion = [NSNumber numberWithInteger:0];
                }
                [[NSUserDefaults standardUserDefaults] setObject:numVersion forKey:WclBuildVersion];
            }
        }
        ws.isRun = YES;
    } failure:^(NSError *error) {
        
        ws.isRun = YES;
    }];
}

- (BOOL)isShowTrade {
    return NO;
    NSNumber *numVersion = [[NSUserDefaults standardUserDefaults] objectForKey:WclBuildVersion];
    if (numVersion == nil) {
        return NO;
    }
    
    NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
    NSString *buildVersion = [infoDictionary objectForKey:@"CFBundleVersion"];
    
    if ([buildVersion integerValue] > [numVersion integerValue]) {
        return NO;
    }else{
        return YES;
    }

}


@end
